package org.cunamas.core.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import javax.sql.DataSource;

import org.cunamas.core.dao.TAAComidaDao;
import org.cunamas.core.dto.Comida;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;


@Repository
public class TAAComidaDaoImpl  implements TAAComidaDao{
	
	JdbcTemplate jdbcTemplate;

	@Autowired
	public void setJdbcTemplate(DataSource dataSource) {
		 this.jdbcTemplate = new JdbcTemplate(dataSource);
	}
	
	
	public List<Comida>  retonaListaComida(int codcom){
		  System.out.println("CODCOM DAO"+codcom);
		  String sql = "select a.CODCOM, a.nom from TAAComida a where codcom <= ?";
		  RowMapper rowMapper =  new RowMapper<Comida>() {
				public Comida mapRow(ResultSet rs, int rowNum) throws SQLException {
					Comida comida = new Comida();
					comida.setCodcom(rs.getInt(1));
					comida.setNom(rs.getString(2));
					return comida;
				}
	
		 };
		  
		return jdbcTemplate.query(sql, new Object[] {codcom},rowMapper);
	  }
	
	

}
